package cn.itcast.reentrantlock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

@Slf4j(topic = "c.Demo01")
public class Demo01 {
    private static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        method1();
    }

    private static void method1(){
        lock.lock();
        try {
          log.debug("method1");
          method2();
        }finally {
            lock.unlock();
        }
    }

    private static void method2(){
        lock.lock();
        try {
            log.debug("method2");
            method3();
        }finally {
            lock.unlock();
        }
    }

    private static void method3(){
        lock.lock();
        try {
            log.debug("method3");
        }finally {
            lock.unlock();
        }
    }
}
